package entities;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Scanner;


/**
 * @author Idan
 * This class is used to read and store parameters from the config.properties file.
 *
 */
public class ConnectParameters 
{
	
	private String host;
	private String port;
	private String virtualHost;
	private String username;
	private String password;
	private String email;
	
	
	
	
	
	public String getHost() {
		return host;
	}
	public void setHost(String host) {
		this.host = host;
	}
	public String getPort() {
		return port;
	}
	public void setPort(String port) {
		this.port = port;
	}
	public String getVirtualHost() {
		return virtualHost;
	}
	public void setVirtualHost(String virtualHost) {
		this.virtualHost = virtualHost;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	
	/*
	 * Reads the parameters from the config.propertires file and sets the object's
	 * properties.
	 * 
	 */
	public boolean readParameters()
	{
		
		String result = "";
		Properties prop = new Properties();
		//String propFileName = "./config/config.properties";
		String propFileName = "./config.properties";
		 
		InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
		 
		if (inputStream != null)
		{
			try
			{
				prop.load(inputStream);
				
				
				  
				String host = prop.getProperty("host");
				String port = prop.getProperty("port");
				String virtualHost = prop.getProperty("virtualHost");
				String username = prop.getProperty("username");
				String password = prop.getProperty("password");
				 
				result = host + " " + port + " " + virtualHost + " " + username + " " + password;
			//	System.out.println(result);
				
				setHost(host);
				setPort(port);
				setVirtualHost(virtualHost);
				setUsername(username);
				setPassword(password);
				
				return true;
				
				
				
			} 
			catch (IOException e)
			{
				// TODO Auto-generated catch block
				//e.printStackTrace();
				return false;
			}
		}
		 
		return false;
      
		}
		
		
/*
 * Reads the email from the config.properties file,
 * used by the Polish station.		
 */
	public boolean readEmail()
	{
		
		String result = "";
		Properties prop = new Properties();
		//String propFileName = "./config/config.properties";
		String propFileName = "./config.properties";
		 
		InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
		 
		if (inputStream != null)
		{
			try
			{
				prop.load(inputStream);
				
				
				  
				String email = prop.getProperty("email");
				
				setEmail(email);
				return true;
				
				
				
				
			} 
			catch (IOException e)
			{
				// TODO Auto-generated catch block
				//e.printStackTrace();
				return false;
			}
		}
		 
		return false;
      
		}

	
		
	
	
}
